/** COPYRIGHT(C) 2008. Loc Phan. All Rights Reserved.
A component class that animate a car
@author Loc Phan
@version 1.01 2008-11-26
*/

package edu.sjsu.cs.phan.hw6;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComponent;
import javax.swing.Timer;

public class CarComponent extends JComponent
{
   /**Constructs a component
    * 
    */
   public CarComponent()
   {
      car = new Car(0,0,Color.red);
      listener = new TimerListener();
      t = new Timer(DELAY, listener);
      t.start();
   }
   /**
    * Draws component
    */
   public void paintComponent(Graphics g)
   {
      Graphics2D g2 = (Graphics2D) g;
      car.draw(g2);
   }
   /**A listener class to listen 
    * to all the actions and do tasks
    * 
    *
    */
   class TimerListener implements ActionListener
   {
      public void actionPerformed(ActionEvent e)
      {
         car.move(50);
         repaint();
         
      }
      
   }
   
   private Car car;
   private ActionListener listener;
   private Timer t;
   public static final int DELAY = 1000;
}
